//
//  ServiceAPI.swift
//  Health-Doctor
//
//  Created by 勇胡 on 2024/9/10.
//  Copyright © 2024 掌上卫健. All rights reserved.
//体检+随访各种服务的直连

import Foundation
import Moya

let serviceProvider = MoyaProvider<ServiceAction>(session:ServiceAction.custoSession(),plugins:NetworkLoggerPlugin.plugins())

enum ServiceAction {
    //蜗牛格式数据转云平台格式数据
    case woniuScreeningStyleToCloudStyle(param:[String:Any])
}

extension ServiceAction: TargetType {
    var baseURL: URL {
        return URL(string: "https://wnjk.2woniu.cn")!
    }
    
    var path: String {
        
        var detailPath = ""
        switch self {
            
        case .woniuScreeningStyleToCloudStyle:
            detailPath = "cloudauth/screening/trans"
        }
        return detailPath
    }
    
    var params: [String:Any] {
        var params:[String:Any] = [:]
        switch self {
        case .woniuScreeningStyleToCloudStyle(let param):
            for (k,v) in param {
                params[k] = v
            }
            
        }
        return params
        
    }
    
    var headers: [String : String]? {
        //
        return getHttpHeader(token: "")
    }
    
    var method: Moya.Method {
        return .post
    }
    
    var sampleData: Data {
        return "{}".data(using: String.Encoding.utf8)!
    }
    
    var task: Task {
        
        if self.method == .get {
            return.requestParameters(parameters: self.params, encoding:GetEncoding())
        }
        return.requestParameters(parameters: self.params, encoding:JSONEncoding())
    }
}
